package com.yanqu.road.server.cmd.newmonopolymkt;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.entity.systemgroup.newmonopolymarket.NewMonopolyMarketUserData;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.newmonopolymkt.NewMonopolyMarketProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.newmonopolymkt.NewMonopolyMarketModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.systemgroup.newmonopolymarket.NewMonopolyMarketMgr;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.string.StringUtils;

@Cmd(code = GameProtocol.S_NEW_MONOPOLY_MARKET_GET_RANK_REWARD_FROM_CROSS, desc = "领取榜单奖励")
public class NewMonopolyMarketGetRankRewardCmdFromCross extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        NewMonopolyMarketProto.NewMonopolyMarketGetRankRewardRespMsg respMsg = NewMonopolyMarketProto.NewMonopolyMarketGetRankRewardRespMsg.parseFrom(packet.getBytes());

        NewMonopolyMarketUserData userData = player.getModule(NewMonopolyMarketModule.class).userData;
        if(userData == null){
            NewMonopolyMarketMgr.getLogger().info("新榷场 getReward user null");
            return;
        }
        if(respMsg.getType() == 1 && userData.isGetServerReward()){
            return;
        }
        if(respMsg.getType() == 1){
            userData.setGetServerReward(true);
        }
        if(respMsg.getType() == 0){
            userData.setGetUserReward(true);
        }
        eLogMoneyType son = eLogMoneyType.NewMonopolyMarketUserRankReward;
        if(respMsg.getType() == 1){
            son = eLogMoneyType.NewMonopolyMarketServerRankReward;
        }
        if(!StringUtils.isNullOrEmpty(respMsg.getReward())){
            player.getModule(CurrencyModule.class).addCurrency(respMsg.getReward(), eLogMoneyType.NewMonopolyMarket, son);
        }
        player.sendPacket(Protocol.U_NEW_MONOPOLY_MARKET_GET_RANK_REWARD, respMsg.toBuilder());
        player.getModule(NewMonopolyMarketModule.class).synRoleData();
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
